public class ObserverProxy implements Observer{
	private class AcceptThread extends Thread {
		NetProxy netProxy;
		int port_num;
		boolean initialized;
		
		public AcceptThread(int port_num_in)
		{
			netProxy = new NetProxy();
			port_num = port_num_in;
			initialized = false;
		}
		
		public void run() {
			netProxy.initialize("localhost", port_num, true);
			initialized = true;
		}
		
		public NetProxy getNetProxy() {
			if (initialized)
				return netProxy;
			else
				return null;
		}
	}
	private AcceptThread acceptThread;
	private Subject subject;
	
	public ObserverProxy(int port_num_in) {
		subject  = null;
		acceptThread = new AcceptThread(port_num_in);
		acceptThread.start();
	}
	@Override
	public void setSubject(Subject s) {
		// TODO Auto-generated method stub
		subject = s;
	}

	@Override
	public Subject getSubject() {
		// TODO Auto-generated method stub
		return subject;
	}

	@Override
	public void update() {
		// TODO Auto-generated method stub
		NetProxy netProxy = acceptThread.getNetProxy();
		if (netProxy != null)
			netProxy.sendMessage(Integer.toString(subject.getData()));
	}

}
